博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PHP24 自定义分页类
阅读量:5283 次
发布时间:2019-06-14

本文共 4921 字,大约阅读时间需要 16 分钟。

分页类的定义

"个记录", "prev"=>"上一页", "next"=>"下一页", "first"=>"首 页", "last"=>"尾 页"); private $linkNum=8;//分页相关按钮数目设置 /* * $total * $listRows */ public function __construct($totalCount, $pageSize=10, $pageURI=""){ $this->totalCount=$totalCount; $this->pageSize=$pageSize; $this->uri=$this->getUri($pageURI); $this->pageIndex=!empty($_GET["pageIndex"]) ? $_GET["pageIndex"] : 1; $this->totalPage=ceil($this->totalCount/$this->pageSize); $this->limit=$this->setLimit(); } private function setLimit(){ return "Limit ".($this->pageIndex-1)*$this->pageSize.", {$this->pageSize}"; } private function getUri($pageURI){ $url=$_SERVER["REQUEST_URI"].(strpos($_SERVER["REQUEST_URI"], '?')?'':"?").$pageURI; $parse=parse_url($url); if(isset($parse["query"])){ parse_str($parse['query'],$params); unset($params["pageIndex"]); $url=$parse['path'].'?'.http_build_query($params); } return $url; } function __get($args){ if($args=="limit") return $this->limit; else return null; } private function start(){ if($this->totalCount==0) return 0; else return ($this->pageIndex-1)*$this->pageSize+1; } private function end(){ return min($this->pageIndex*$this->pageSize,$this->totalCount); } private function first(){ $html = ""; if($this->pageIndex==1) $html.=''; else $html.="  {$this->config["first"]}  "; return $html; } private function prev(){ $html = ""; if($this->pageIndex==1) $html.=''; else $html.="  {$this->config["prev"]}  "; return $html; } private function pageList(){ $linkPage=""; $inum=floor($this->linkNum/2); for($i=$inum; $i>=1; $i--){ $pageIndex=$this->pageIndex-$i; if($pageIndex<1) continue; $linkPage.=" {$pageIndex} "; } $linkPage.=" {$this->pageIndex} "; for($i=1; $i<=$inum; $i++){ $pageIndex=$this->pageIndex+$i; if($pageIndex<=$this->totalPage) $linkPage.=" {$pageIndex} "; else break; } return $linkPage; } private function next(){ $html = ""; if($this->pageIndex==$this->totalPage) $html.=''; else $html.="  {$this->config["next"]}  "; return $html; } private function last(){ $html = ""; if($this->pageIndex==$this->totalPage) $html.=''; else $html.="  {$this->config["last"]}  "; return $html; } private function goPage(){ return '    '; } function fpage($display=array(0,1,2,3,4,5,6,7,8)){ $html[0]="  共有{$this->totalCount}{$this->config["header"]}  "; $html[1]="  每页显示".($this->end()-$this->start()+1)."条,本页{$this->start()}-{$this->end()}条  "; $html[2]="  {$this->pageIndex}/{$this->totalPage}页  "; $html[3]=$this->first(); $html[4]=$this->prev(); $html[5]=$this->pageList(); $html[6]=$this->next(); $html[7]=$this->last(); $html[8]=$this->goPage(); $fpage=''; foreach($display as $index){ $fpage.=$html[$index]; } return $fpage; }}

  

  

在控制器中使用分页类

display(); } /**分页留言数据*/ public function listgb() { $pageIndex = isset($_GET['pageIndex']) ? $_GET['pageIndex'] : 1; $pageSize = isset($_GET['pageSize']) ? $_GET['pageSize'] : 10; $like = isset($_GET['like']) ? $_GET['like'] : null; $gm = new GbmgrModel(); //获得符合条件的总记录数 $totalCount = $gm->count($like); //获得分页数据 $list = $gm->list($pageIndex, $pageSize, $like); $url = "index.php?g=admin&c=page&a=listgb&pageIndex={pageIndex}"; $myPage=null; if ($totalCount > $pageSize) {//总记录数大于每页显示数,显示分页 $myPage = new \core\MyPage($totalCount, $pageSize, $pageIndex, $url, 2); } $this->assign('list',$list); $this->assign("myPage",$myPage); $this->display(); }}

  

视图定义

    
Page类分页
data['list'] as $value){ echo "
"."
"."
"."
"."
"."
"."
"; } ?>
编号 姓名 邮箱 电话 留言
".$value['id']. " ".$value['uname']. " ".$value['uemail']. " ".$value['uphone']. " ".$value['umessage']. "
data['myPage']->outPages();?>

  

转载于:https://www.cnblogs.com/rask/p/9322454.html

你可能感兴趣的文章
系统设计与分析(六)
查看>>
Java IO-1 File类
查看>>
HW5.29
查看>>
Linux查看物理CPU个数,核数,逻辑CPU个数;内存信息
查看>>
sqlserver查询效率
查看>>
FoxMail邮件设置
查看>>
percona-toolkit 之 【pt-online-schema-change】说明
查看>>
[模板]大数加法
查看>>
ZeroBrane Lua脚本编辑器代码自动补全
查看>>
linux下播放mp3
查看>>
POJ1611-The Suspects-并查集
查看>>
笔记--cocos2d-x 3.0 环境搭建
查看>>
关于不断刷新界面jsp+ajax
查看>>
js高阶函数应用—函数防抖和节流
查看>>
eclipse 中java/scala 混合的maven项目 工作环境篇
查看>>
顺序栈与两栈共享空间-C语言实现
查看>>
【mongo】可以用localhost启动,无法用ip启动问题的解决
查看>>
【QT】视频播放
查看>>
揭开Redis的神秘面纱
查看>>
Object流
查看>>